//
//  SystemViewController.m
//  hello mui
//
//  Created by zhangtao on 15/9/16.
//  Copyright (c) 2015年 zt.td. All rights reserved.
//

#import "SystemViewController.h"
#import "SetSystemViewController.h"
#import "AboutSoftwareViewController.h"
#import "LoginAndRegistViewController.h"
#import "HelpViewController.h"
#import "MainTabBarViewController.h"

@interface SystemViewController ()<UIAlertViewDelegate>
@property (weak, nonatomic) IBOutlet UIButton *loginOut;
@property (strong, nonatomic) IBOutlet UIView *loginOutView;
@property (weak, nonatomic) IBOutlet UIView *VO;
@property (weak, nonatomic) IBOutlet UIView *TO;
@property (weak, nonatomic) IBOutlet UIView *THO;

@end

@implementation SystemViewController

//-(void)viewWillAppear:(BOOL)animated{
//    self.tabBarController.tabBar.hidden = YES;
//}
//
//-(void)viewWillDisappear:(BOOL)animated{
//    self.tabBarController.tabBar.hidden = NO;
//}

-(void)initView{
  
}



- (void)viewDidLoad {
    self.title = @"系统设置";
    self.view.backgroundColor = VIEWCO;
    [super viewDidLoad];
    self.navigationController.navigationBar.tintColor = [UIColor whiteColor];
    _loginOut.layer.cornerRadius = 15;
    
    _VO.layer.borderColor = _TO.layer.borderColor = _THO.layer.borderColor = _loginOutView.layer.borderColor = rgb_box;
    _loginOutView.layer.borderWidth = _VO.layer.borderWidth = _TO.layer.borderWidth = _THO.layer.borderWidth = 1;
    
}
- (IBAction)setSystem:(id)sender {
    SetSystemViewController *setSystem = [[SetSystemViewController alloc]initWithNibName:@"SetSystemViewController" bundle:nil];
    [self.navigationController pushViewController:setSystem animated:YES];
}
- (IBAction)loginOut:(id)sender {
    if (NSUSER_DEF(@"USERID")) {
        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"主人， 你真的要离开我吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
        [alert show];

    }
    else{
        [ToolObjc showMessage:@"您还没有登陆"];
    }
}

-(void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex{
    switch (buttonIndex) {
        case 0:
            
            break;
            case 1:
            [self out];
            break;
        default:
            break;
           
    }
}

-(void)out{
    
    [ToolObjc loginOut];

    
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
//    LoginAndRegistViewController *login = [storyboard instantiateViewControllerWithIdentifier:@"loginAndRegist"];
    MainTabBarViewController *main = [storyboard instantiateViewControllerWithIdentifier:@"main"];
    NSUserDefaults *def = [NSUserDefaults standardUserDefaults];
//    [self presentViewController:main animated:YES completion:nil];
    [def removeObjectForKey:SHARE];
    [def removeObjectForKey:@"USERHEADER"];
    [def removeObjectForKey:@"NICKNAME"];
    [def removeObjectForKey:@"GENDER"];
    [def removeObjectForKey:@"USERID"];
    [def removeObjectForKey:@"SCHOOL"];
    [def removeObjectForKey:@"GRADE"];
    [def removeObjectForKey:@"SEX"];
    [def removeObjectForKey:@"PHONENUM"];
    [def removeObjectForKey:@"LOGINPHONE"];
    [def removeObjectForKey:@"GROUP"];
    [def removeObjectForKey:@"DATA"];
    [def removeObjectForKey:@"LOCALUSERHEADER"];
    [def removeObjectForKey:@"SELECTVALUE"];
    [def removeObjectForKey:@"HEADIMG"];
    
    [self presentViewController:main animated:NO completion:nil];
}

- (IBAction)aboutSoftWare:(id)sender {
    AboutSoftwareViewController *soft  =
    [[AboutSoftwareViewController alloc]initWithNibName:@"AboutSoftwareViewController" bundle:nil];
    [self.navigationController pushViewController:soft animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (IBAction)check:(id)sender {
//    [ToolObjc showMessage:@"当前已是最新版本"];
    
    [ToolObjc shoVersionMessage:@"当前已是最新版本"];
//    UIAlertView *alert = [[UIAlertView alloc]initWithTitle:nil message:@"已是最新版本" delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
//    [alert show];
//    
//    NSString *path = @"http://www.fenghuang.org/study-manager/version/updateVersion";
//    AFHTTPRequestOperationManager *manager = [AFHTTPRequestOperationManager manager];
//    [manager setResponseSerializer:[AFHTTPResponseSerializer serializer]];
//    [manager POST:path parameters:nil success:^(AFHTTPRequestOperation *operation, id responseObject) {
//        NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:responseObject options:NSJSONReadingMutableLeaves error:nil];
//        NSString *version = [dic
//                             valueForKey:@"version"];
//        NSString *remark = [dic valueForKey:@"remark"];
//        NSString *url = [dic valueForKey:@"url"];
//        
//        
//        NSLog(@"//login//%@",dic);
//        UIAlertView *alert = [[UIAlertView alloc]initWithTitle:[NSString stringWithFormat:@"版本:%@",version] message:[NSString stringWithFormat:@"下载地址:%@",url] delegate:nil cancelButtonTitle:nil otherButtonTitles:@"确定", nil];
//        [alert show];
//        
//    } failure:^(AFHTTPRequestOperation *operation, NSError *error) {
//        
//        //
//    }];
    

    
}
- (IBAction)help:(id)sender {
    HelpViewController *help = [[HelpViewController alloc]initWithNibName:@"HelpViewController" bundle:nil];
    [self.navigationController pushViewController:help animated:YES];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
